package com.jiyun.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.UUID;

@RestController
@RequestMapping("/upload")
public class UploadController {

    //这是一个超级牛的上传
    @RequestMapping("/uploadLocal")
    public String uploadLocal(MultipartFile file) throws Exception{
        //李四，你不要动，用我这个
        String filePath = "D:/a/";
        File fileParent = new File(filePath);
        if(!fileParent.exists()){
            fileParent.mkdirs();
        }
        String fileName = UUID.randomUUID().toString()+file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        file.transferTo(new File(filePath+fileName));
        return "/photo/"+fileName;
    }

}
